package com.uphone.kingmall.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.china.zhuoyue.R;
import com.uphone.kingmall.bean.GoodsDetailBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 规格适配器2
 */

public class ShopsCartPwAdapter2 extends RecyclerView.Adapter<ShopsCartPwAdapter2.ViewHolder> {


    private Context context;
    private List<GoodsDetailBean.GoodsBean.PropsBean.PropBean> list;

    public ShopsCartPwAdapter2(Context context, List<GoodsDetailBean.GoodsBean.PropsBean.PropBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.kingmall_item_goodspw2, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.tvTypeName2.setText(list.get(position).getGoodsPropVal());
        if (list.get(position).isSelect() == 1) {
            holder.tvTypeName2.setTextColor(context.getResources().getColor(R.color.colorTextSelect));
            holder.tvTypeName2.setBackgroundResource(R.drawable.shape_bg_ffeff1_red_yuan);
        } else {
            holder.tvTypeName2.setTextColor(context.getResources().getColor(R.color.colorText));
            holder.tvTypeName2.setBackgroundResource(R.drawable.shape_bg_eeeeee_yuan);
        }
        holder.tvTypeName2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                itemClickListener.onItemClick(v, position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_type_name2)
        TextView tvTypeName2;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    OnItemClickListener itemClickListener;

    public void setOnItemClickListener(OnItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }

}
